<?php

namespace Biz\Mailers\App\Tags;

use Biz\Mailers\MailerTags;
use Biz\Models\App\AppSite;
use Illuminate\Support\Facades\Log;
use Biz\Constants\ContainerConstants;

/**
 * SiteTags.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class AppSiteTags extends MailerTags
{
    /**
     * @var AppSite
     */
    protected $appSite;

    /**
     * SiteTags constructor.
     *
     * @param AppSite $appSite
     */
    public function __construct(AppSite $appSite = null)
    {
        $this->appSite = $appSite;

        $this->supportTags();
    }

    /**
     * Support Tags.
     */
    public function supportTags(): void
    {
//        if (is_null($this->appSite)) {
//            $this->initSite();
//        }

        if ($this->appSite) {
            $this->tags['SiteUrl']  = $this->appSite->domain;
            $this->tags['SiteName'] = $this->appSite->name;
        } else {
            $this->tags['SiteUrl']  = 'Unknown';
            $this->tags['SiteName'] = 'Unknown';
        }
    }

//    /**
//     * Init Site.
//     */
//    public function initSite()
//    {
//        if (app('app')->has(ContainerConstants::BIZ_APP_SITE)) {
//            $this->siteEmail = app(ContainerConstants::BIZ_APP_SITE);
//            Log::debug('SiteTags InitSite Success');
//        }
//    }

//    /**
//     * Check site.
//     *
//     * @throws \Lumen\Core\Exceptions\BusinessException
//     *
//     * @return bool
//     */
//    public function checkSite(): bool
//    {
//        $site_id = app('request')->get('site_id', null);
//        if (is_null($site_id)) {
//            return false;
//        }
//
//        //$service = new AppSiteService(new AppSiteRepository());
//
//        $site = AppSite::find($site_id);
//        if ($site instanceof AppSite) {
//            $this->site = $site;
//
//            return true;
//        }
//
//        return false;
//    }
}
